package lesson03;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class ImageIconDemo extends JFrame {
  public  ImageIconDemo (){
      //获取图片地址

      JLabel lb=new JLabel("ImageIcon");
     URL url = ImageIconDemo.class.getResource("tx.jpg");

      ImageIcon ig=new ImageIcon(url); //命名不要冲突
      lb.setIcon(ig);
     lb.setHorizontalAlignment(SwingConstants.CENTER);

      Container ct=getContentPane();
      ct.add(lb);

     setVisible(true);
     setBounds(200,200,400,400);
     setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  }

    public static void main(String[] args) {
    new ImageIconDemo();
    }

}
